import { asyncRoutes, constantRoutes } from '@/router'

const state = {}
const mutations = {
  setRoutes(state, data) {
    state.routes = [...constantRoutes, ...data]
  }
}
const actions = {
  fiterRoutes(store, menus) {
    // 根据用户的权限列表(调用时传进来)
    // 动态路由的数组
    // 一起筛选的出有权限的路由列表
    console.log('actions 的调用')
    const routes = asyncRoutes.filter(el => menus.includes(el.name))
    // console.log(routes)
    store.commit('setRoutes', routes)

    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
